<template>
	<view>
		<view class="product">
			<view class="product-list">
				<view class="product-list-item" v-for="(it,index) in list" @click="toDetail(it)">
					<image :src="it.banner + '?imageView2/1/w/280/h/210'" mode="aspectFill" class="product-list-item-img"></image>
					<view class="product-list-item-r">
						<view class="product-list-item-r-title">{{it.name || ''}}</view>
						<!-- <view class="product-list-item-r-guige">
							规格: 5杆/7套
						</view> -->
						<view class="product-list-item-r-price">
							￥{{it.price || ''}}
							<span>已售{{it.Sales || 0}}件</span>
						</view>
						
						<view class="product-list-item-r-btn">
							<view style="margin-right: 20rpx;" @click.stop>
								<u-button type="info" shape="circle" size="mini" :text="it.recommend === 0 ? '推荐' : '取消推荐'" @click.stop="recommend(it,index)"></u-button>
							</view>
							<view @click.stop>
								<u-button type="error" :plain="true" shape="circle" size="mini" text="移除" @click.stop="addDistribution(it)"></u-button>
							</view>
							
							
						</view>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		goodsstores_recommend,
		goodsDistribution,
		InformationUserInfo
	} from '@/common/http/api.js'
	export default {
		props:['list'],
		data(){
			return {
				userInfo: ''
			}
		},
		created() {
			InformationUserInfo().then(res=>{
				this.userInfo = res.data
			})
		},
		methods:{
			toDetail(it){
				//id=53&type=3&business_card_id=&nickname=
				uni.navigateTo({
					url:`/pagesA/shopping/detail?id=${it.id}&type=3&business_card_id=&nickname=` + this.userInfo.nickname
				})
			},
			addDistribution(it){
				uni.showLoading()
				goodsDistribution({id: it.id,business_card_id: it.business_card_id}).then(res=>{
					uni.hideLoading()
					this.$emit('reload')
				})
			},
			recommend(it,index){
				uni.showLoading()
				goodsstores_recommend({business_card_id:it.business_card_id, id: it.id}).then(res=>{
					uni.hideLoading()
					if(it.recommend === 0) {
						uni.showToast({duration:3000,
							title: '添加成功！',
							icon: 'none'
						})
						
					} else {
						uni.showToast({duration:3000,
							title: '已取消推荐！',
							icon: 'none'
						})
						
					}
					this.$emit('recommend',it,index)
				})
				
			},
			getOrderStatus(status) {
				// 0-待支付，1-待发货，2-已发货(不用)，3-运输中，4-已完成，5-退款申请中，6-退款拒绝，7-退款成功，8-介入中，9同意退货（输入运单号,10等待商家退款
				let OrderStatus = [{
						label: '待支付',
						value: 0
					},
					{
						label: '待发货',
						value: 1
					},
					{
						label: '已发货',
						value: 2
					},
					{
						label: '运输中',
						value: 3
					},
					{
						label: '已完成',
						value: 4
					},
					{
						label: '退款申请中',
						value: 5
					},
					{
						label: '退款拒绝',
						value: 6
					},
					{
						label: '退款成功',
						value: 7
					},
					{
						label: '介入中',
						value: 8
					},
					{
						label: '同意退货',
						value: 9
					},
					{
						label: '等待退款',
						value: 10
					}
				]
				let name = ''
				try {
					name = OrderStatus.find(i => i.value === status).label
				} catch (e) {
			
				}
				return name
			},
		}
	}
</script>

<style lang="scss" scoped>
	.product {
		width: 690rpx;
		margin: 0 auto;
		padding-top: 20rpx;
		.product-list {
			width: 100%;
			.product-list-item {
				width: 100%;
				display: flex;
				height: 210rpx;
				border-radius: 20rpx;
				background: #fff;
				box-shadow: 0rpx 0rpx 5rpx #F6F7F8; 
				margin-bottom: 20rpx;
				.product-list-item-img {
					width: 280rpx;
					height: 210rpx;
					border-top-left-radius: 20rpx;
					border-bottom-left-radius: 20rpx;
					margin-right: 20rpx; 
				}
				.product-list-item-r {
					min-width: 0;
					flex: 1;
					box-sizing: border-box;
					padding: 20rpx;
					.product-list-item-r-title {
						font-size: 28rpx;
						font-weight: bold;
						margin-bottom: 20rpx;
						overflow: hidden;
						text-overflow: ellipsis;
						white-space: nowrap;
					}
					.product-list-item-r-guige {
						width: fit-content;
						background: #F8F8F8;
						padding: 1rpx 18rpx;
						border-radius: 5rpx;
						font-size: 28rpx;
						color: #A1A0A3;
						margin-bottom: 20rpx; 
					}
					.product-list-item-r-price {
						font-size: 36rpx;
						color: #E7373A;
						margin-bottom: 20rpx;
						span {
							margin-left: 20rpx;
							font-size: 24rpx;
							color: #828186;
						}
					}
					.product-list-item-r-num {
						display: flex;
						justify-content: space-between;
						font-size: 28rpx;
						margin-bottom: 20rpx;
					}
					.product-list-item-r-btn {
						display: flex;
						align-items: center;
						justify-content: flex-end;
						box-sizing: border-box;
						
						&>view {
							width: 100rpx;
						}
					}
					
				}
			}
		}
	}
</style>